package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.TemplateAdapter;
import flc.ast.databinding.ActivityTemplateBinding;
import stark.common.basic.event.EventStatProxy;

public class TemplateActivity extends BaseAc<ActivityTemplateBinding> {

    public static int type;
    private TemplateAdapter templateAdapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_template;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivTemplateBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.rvTemplaateList.setLayoutManager(new GridLayoutManager(mContext, 2));
        templateAdapter = new TemplateAdapter();
        mDataBinding.rvTemplaateList.setAdapter(templateAdapter);
        templateAdapter.addChildClickViewIds(R.id.ivTemplateItemDraw);
        templateAdapter.setOnItemChildClickListener(this);
    }

    @Override
    public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
        switch (view.getId()) {
            case R.id.ivTemplateItemDraw://选择模板
                gotoDraw(templateAdapter.getItem(position));
                break;
        }
    }

    @Override
    protected void initData() {
        if (type == 1) {
            mDataBinding.tvTemplateTitle.setText(getString(R.string.template_type1));
            getJsData();
        } else if (type == 2) {
            mDataBinding.tvTemplateTitle.setText(getString(R.string.template_type2));
            getQbData();
        } else if (type == 3) {
            mDataBinding.tvTemplateTitle.setText(getString(R.string.template_type3));
            getZwData();
        } else if (type == 4) {
            mDataBinding.tvTemplateTitle.setText(getString(R.string.template_type4));
            getDwData();
        } else if (type == 5) {
            mDataBinding.tvTemplateTitle.setText(getString(R.string.template_type5));
            getQtData();
        }
    }

    //展示角色数据
    private void getJsData() {
        List<Integer> listJs = new ArrayList<>();
        listJs.add(R.drawable.dm1);
        listJs.add(R.drawable.dm2);
        listJs.add(R.drawable.dm3);
        listJs.add(R.drawable.dm4);
        listJs.add(R.drawable.dm5);
        listJs.add(R.drawable.dm6);
        listJs.add(R.drawable.dm7);
        listJs.add(R.drawable.dm8);
        templateAdapter.setList(listJs);
    }

    //展示Q版数据
    private void getQbData() {
        List<Integer> listQb = new ArrayList<>();
        listQb.add(R.drawable.qb1);
        listQb.add(R.drawable.qb2);
        listQb.add(R.drawable.qb3);
        listQb.add(R.drawable.qb4);
        listQb.add(R.drawable.qb5);
        listQb.add(R.drawable.qb6);
        listQb.add(R.drawable.qb7);
        listQb.add(R.drawable.qb8);
        templateAdapter.setList(listQb);
    }

    //展示植物数据
    private void getZwData() {
        List<Integer> listZw = new ArrayList<>();
        listZw.add(R.drawable.zw1);
        listZw.add(R.drawable.zw2);
        listZw.add(R.drawable.zw3);
        listZw.add(R.drawable.zw4);
        listZw.add(R.drawable.zw5);
        listZw.add(R.drawable.zw6);
        listZw.add(R.drawable.zw7);
        listZw.add(R.drawable.zw8);
        templateAdapter.setList(listZw);
    }

    //展示动物数据
    private void getDwData() {
        List<Integer> listDw = new ArrayList<>();
        listDw.add(R.drawable.dw1);
        listDw.add(R.drawable.dw2);
        listDw.add(R.drawable.dw3);
        listDw.add(R.drawable.dw4);
        listDw.add(R.drawable.dw5);
        listDw.add(R.drawable.dw6);
        listDw.add(R.drawable.dw7);
        listDw.add(R.drawable.dw8);
        templateAdapter.setList(listDw);
    }

    //展示其他数据
    private void getQtData() {
        List<Integer> listQt = new ArrayList<>();
        listQt.add(R.drawable.qt1);
        listQt.add(R.drawable.qt2);
        listQt.add(R.drawable.qt3);
        listQt.add(R.drawable.qt4);
        listQt.add(R.drawable.qt5);
        listQt.add(R.drawable.qt6);
        listQt.add(R.drawable.qt7);
        listQt.add(R.drawable.qt8);
        templateAdapter.setList(listQt);
    }

    //去到绘画界面
    private void gotoDraw(int img) {
        DrawActivity.kind = 1;
        DrawActivity.selImg = img;
        startActivity(DrawActivity.class);
    }

}